﻿
<%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ page import="com.cxx.purchasecharge.component.utils.ComponentConstants"%>
<%@ page import="com.cxx.purchasecharge.component.bean.TimeFrame"%>

<style type="text/css">
#dlg-provider input,#dlg-provider select {
	width: 150px;
}

#dlg-provider #fm-provider div {
	float: left;
	width: 300px;
}

#dlg-provider #fm-provider div label {
	width: 80px;
}
</style>
<script type="text/javascript">
		var showSearchProviderPaymentDialog = function () 
		{
			$('#dlg-view-provider-payment').dialog('open').dialog('setTitle', '查询供应商付款记录');
			setProviderInitialTimeFrame(defaultProviderTimeFrame);
			$('#toolbar-provider-payment #advanceSearchSpan #timeFrame').combobox('setValue', defaultProviderTimeFrame);
			var customer = $('#dg-provider').datagrid('getSelected');
			if(customer) 
			{
				loadComboboxData('#toolbar-provider-payment #advanceSearchSpan #customerId', '<c:url value='/customer/getAllCustomer2.html' />?customerTypeCode=1', customer.id, function() {$('#dg-provider-payment').datagrid('options').onBeforeLoad = onBeforeLoadProviderPayment;
			$('#dg-provider-payment').datagrid('reload');});
			}
			else 
			{
				$('#toolbar-provider-payment #advanceSearchSpan #customerId').combobox('setValue', '');
				$('#dg-provider-payment').datagrid('options').onBeforeLoad = onBeforeLoadProviderPayment;
				$('#dg-provider-payment').datagrid('reload');
			}
		}
		var viewProviderPaymentRecord = function () 
		{
			var row = $('#dg-provider').datagrid('getSelected');
			if (row) {
				$('#dlg-view-provider-payment').dialog('open').dialog('setTitle', row.shortName + '的付款记录');
				loadGridData ('#dg-provider-payment', '<c:url value='/providerPay/getPaymentByProvider.html' />', {providerId : row.id});
			}
		}
		var addProviderPaymentCallback = function () 
		{
			var row = $('#dg-provider').datagrid('getSelected');
			if (row) {
				$('#dlg-add-provider-payment #fm-add-provider-payment #customerId').val (row.id);
				var createDate = new Date().format("yyyy-MM-dd");
				$('#dlg-add-provider-payment #fm-add-provider-payment #payDate').datebox('setValue', createDate);
			}
		}
		
		var onClickProviderRow = function (rowIndex, rowData) 
		{
			$('#toolbar-provider #btn-receivePay').linkbutton('enable');
		}
		var onLoadProviderSuccess = function(data) 
		{
			$('#toolbar-provider #btn-receivePay').linkbutton('disable');
		}
		function doSearchProvider(value) {
			$('#dg-provider').datagrid('load', {
				searchKey : value
			});
		}
		
		var onProviderSelectStartDate = function (date) 
		{
			$('#toolbar-provider-payment #advanceSearchSpan #timeFrame').combobox('setValue', 'CUSTOMIZE');
		}
		var onProviderSelectTimeFrame = function(record) 
		{
			setProviderInitialTimeFrame(record.value);
		}
		var pageInfo = {page: 1, rows: 10};
		var onSearchProviderPaymentByAdvance = function () 
		{
			var startDate = $('#toolbar-provider-payment #advanceSearchSpan #startDate').combo('getValue');
			var endDate = $('#toolbar-provider-payment #advanceSearchSpan #endDate').combo('getValue');
			var customerId = $('#toolbar-provider-payment #advanceSearchSpan #customerId').combo('getValue');
			if((startDate != '' && endDate == '') || (startDate == '' && endDate != '')) 
			{
				$.messager.alert('警告','开始时间和结束时间必须同时填!','warning');
				return;
			}
			if(startDate == '' && endDate == '' && customerId == '') 
			{
				$.messager.alert('警告','请填写查询条件!','warning');
				return;
			}
			//var pageOptions = $('#dg-provider-payment').datagrid('getPager').data("pagination").options;
			//var page = pageOptions.pageNumber;
			//var rows = pageOptions.pageSize;
			loadGridData ('#dg-provider-payment', '<c:url value='/providerPay/getPaymentByProvider2.html' />', {page:pageInfo.page, rows:pageInfo.rows, startDate:startDate, endDate:endDate, customerId:customerId});
		}
		var defaultProviderTimeFrame = 'RECENT_THIRTY_DAYS';
		var onBeforeLoadProviderPayment = function (param) 
		{
			pageInfo = param;
			var startDate = $('#toolbar-provider-payment #advanceSearchSpan #startDate').combo('getValue');
			var endDate = $('#toolbar-provider-payment #advanceSearchSpan #endDate').combo('getValue');
			var customerId = $('#toolbar-provider-payment #advanceSearchSpan #customerId').combo('getValue');
			if(customerId == undefined) 
			{
				customerId = '';
			}
			if(startDate == '' && endDate == '' && customerId == '') 
			{
				var timeFrame = $('#toolbar-provider-payment #advanceSearchSpan #timeFrame').combo('getValue');
				setProviderInitialTimeFrame(timeFrame);
				
				startDate = $('#toolbar-provider-payment #advanceSearchSpan #startDate').combo('getValue');
				endDate = $('#toolbar-provider-payment #advanceSearchSpan #endDate').combo('getValue');
			}
			
			$('#dg-provider-payment').datagrid('options').url = "<c:url value='/providerPay/getPaymentByProvider2.html' />?startDate="+startDate+"&endDate="+endDate+"&customerId="+customerId;
			return true;
		}
		var setProviderInitialTimeFrame = function(timeFrame) 
		{
			var startDate = generateStartDate(timeFrame);
			var endDate = new Date().format("yyyy-MM-dd");
			$('#toolbar-provider-payment #advanceSearchSpan #startDate').datebox('setValue', startDate);
			$('#toolbar-provider-payment #advanceSearchSpan #endDate').datebox('setValue', endDate);
		}
	</script>

	<table id="dg-provider" title="供应商收款" class="easyui-datagrid"
		url="<c:url value='/providerPay/getAll.html' />"
		toolbar="#toolbar-provider" pagination="true" rownumbers="true"
		singleSelect="true" checkOnSelect="true" selectOnCheck="false" showFooter="true" 
		data-options="fitColumns:true, sortName:'dealMoney', sortOrder:'desc', fit:true, onClickRow:onClickProviderRow, onLoadSuccess:onLoadProviderSuccess">
		<thead>
			<tr>
				<th data-options="field:'id',hidden:true"></th>
				<th field="shortName" width="100" sortable="true"><spring:message code="customer.shortName" /></th>
				<th field="contactName" width="100" data-options="formatter:contactNameFormatter, styler:cellStyler_userRole">联系人</th>
				<th field="email" width="100" sortable="true"><spring:message code="customer.email" /></th>
				<th field="fixedPhone" width="100" sortable="true"><spring:message code="customer.fixedPhone" /></th>
				<th field="address" width="50" data-options="styler:cellStyler_userRole"><spring:message code="customer.address" /></th>
				<th field="signUserId" width="100" sortable="true"><spring:message code="customer.signUserId" /></th>
				<th field="dealMoney" width="100" sortable="true" data-options="styler:dealMoney_styler">应付款</th>
			</tr>
		</thead>
	</table>

<div id="toolbar-provider">
	<a id="btn-receivePay" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" disabled="true" 
		onclick="editModel('#dg-provider', '#dlg-add-provider-payment', '付款', '#fm-add-provider-payment', '<c:url value='/providerPay/updatePaid.html' />', addProviderPaymentCallback)"
		title="<spring:message code="selectOneRow" />供应商付款">供应商付款</a> 
	<a id="btn-viewPay" href="javascript:void(0)" class="easyui-linkbutton" 
		iconCls="icon-search" plain="true" onclick="showSearchProviderPaymentDialog()" title="查询供应商付款记录">查询付款记录</a>
	<span style="float: right; margin-right: 5px"> 
		<input class="easyui-searchbox"
			data-options="prompt:'<spring:message code="pleaseInputValue" />',searcher:doSearchProvider" style="width: 200px" />
	</span>
</div>

<!-- 增加付款弹出框 -->
<div id="dlg-add-provider-payment" class="easyui-dialog"
	style="width: 400px; height: 350px; padding: 10px 20px" closed="true"
	buttons="#dlg-buttons-add-provider-payment" data-options="modal:true">
	<form id="fm-add-provider-payment" class="fm" method="post" novalidate>
		<div class="fitem divHidden">
			<input id="customerId" name="customerId">
		</div>
		<div class="fitem">
			<label style="width: 60px;">客户:</label> 
			<input id="shortName" name="shortName" readonly="readonly"
				style="width: 210px; border: none;">
		</div>
		<div class="fitem">
			<label>金额:</label> 
			<input id="paid" name="paid" class="easyui-numberbox" data-options="required:true, min:1, precision:1" />
		</div>
		<div class="fitem">
			<label>支付账号:</label> 
			<input id="paidType" name="accountBean.id" class="easyui-combobox" panelHeight="auto" 
				data-options="valueField:'id', textField:'name', required:true, 
					url: '', editable:false, onShowPanel:onShowPaymentAccount" />
		</div>
		<div class="fitem">
			<label>日期:</label> 
			<input id="payDate" name="payDate" class="easyui-datebox" />
		</div>
		<div class="fitem">
			<label>备注:</label> 
			<input id="comment" name="comment" class="easyui-validatebox" data-options="required:true" />
		</div>
	</form>
</div>
<div id="dlg-buttons-add-provider-payment">
	<a id="add-provider-payment" href="javascript:void(0)"
		class="easyui-linkbutton" iconCls="icon-ok"
		onclick="saveModel('#dg-provider', '#dlg-add-provider-payment', '#fm-add-provider-payment')">
		<spring:message code="save" /></a> 
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel"
		onclick="javascript:$('#dlg-add-provider-payment').dialog('close')">
		<spring:message code="cancel" /></a>
</div>
<!-- 增加付款弹出框 -->

<!-- 查看付款记录弹出框 -->
<div id="dlg-view-provider-payment" class="easyui-dialog"
	style="width: 750px; height: 470px; padding: 5px;" closed="true"
	buttons="#dlg-buttons-view-provider-payment" data-options="modal:true">
	<div id="" style="">
		<table id="dg-provider-payment" class="easyui-datagrid"
			style="width: 700px; height: 380px" url="" rownumbers="true"
			singleSelect="true" fitColumns="true" showFooter="true" toolbar="#toolbar-provider-payment" data-options="pagination:true">
			<thead>
				<tr>
					<th data-options="field:'id',hidden:true"></th>
					<th field="<%=ComponentConstants.PAY_DATE%>" width="100"><spring:message code="order.payDate" /></th>
					<th field="customerName" width="50">供应商</th>
					<th field="operator" width="50">操作者</th>
					<th field="orderId" width="100">订单号</th>
					<th field="<%=ComponentConstants.PAID%>" width="50" data-options="styler:dealMoney_styler">应付额</th>
					<th field="allUnPaid" width="50">未付总额</th>
					<!-- <th field="paymentName" width="150"
						data-options="formatter: paymentFormatter">账号</th> -->
					<th field="comment" width="150">备注</th>
				</tr>
			</thead>
		</table>
	</div>
</div>
<div id="toolbar-provider-payment" style="padding:5px;height:auto">
	<div>
		<span id="advanceSearchSpan" style="width: 610px; display: inline-block;">
			<form id="" action="">
            	时间:<input id="startDate" name="startDate" class="easyui-datebox" style="width:100px" 
				editable="false" title="开始时间" data-options="onSelect: onProviderSelectStartDate">
				- <input id="endDate" name="endDate" class="easyui-datebox" style="width:100px" 
				editable="false" title="结束时间" data-options="onSelect: onProviderSelectStartDate">&nbsp;
				<select id="timeFrame" name="timeFrame" class="easyui-combobox" style="width:80px" panelHeight="auto" editable="false" data-options="onSelect: onProviderSelectTimeFrame">
					<option value="CUSTOMIZE"><%=TimeFrame.CUSTOMIZE.getText () %></option>
					<option value="TODAY"><%=TimeFrame.TODAY.getText () %></option>
					<option value="RECENT_THREE_DAYS"><%=TimeFrame.RECENT_THREE_DAYS.getText () %></option>
					<option value="RECENT_SEVEN_DAYS"><%=TimeFrame.RECENT_SEVEN_DAYS.getText () %></option>
					<option value="RECENT_FIFTEEN_DAYS"><%=TimeFrame.RECENT_FIFTEEN_DAYS.getText () %></option>
					<option value="RECENT_THIRTY_DAYS" selected="selected"><%=TimeFrame.RECENT_THIRTY_DAYS.getText () %></option>
					<option value="CURRENT_MONTH"><%=TimeFrame.CURRENT_MONTH.getText () %></option>
				</select>
				&nbsp;
				客户:<input id="customerId" name="customerId" class="easyui-combobox" style="width:100px" data-options="valueField:'id',
											textField:'shortName',
											url:'',
											mode:'local',
											filter:comboboxFilter,
											onShowPanel:onClickProviderCombox" />
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" title="查询出库单" onclick="onSearchProviderPaymentByAdvance()">查询</a>
			</form>
        </span>
	</div>
</div>
<div id="dlg-buttons-view-provider-payment">
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel"
		onclick="javascript:$('#dlg-view-provider-payment').dialog('close')">关闭</a>
</div>
<!-- 查看付款记录弹出框 -->
